{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">阿里云OSS配置</h3>
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray-4">AccessKey ID<font>*</font>
			</td>
			<td>
				<input type="hidden" name="id" value="{$id}">
				<input type="text" name="accessKeyId" lay-verify="required" autocomplete="off" placeholder="请输入AccessKey ID"
					lay-reqText="请输入AccessKey ID" class="layui-input" {notempty name="$config.accessKeyId" }
					value="{$config.accessKeyId}" {/notempty} style="width:300px;display: inline-block;">
				<span
					style="color:#999; font-size:12px;">如：LTAI**********Z7fkT</span>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray-4">AccessKey Secret<font>*</font>
			</td>
			<td>
				<input type="text" name="accessKeySecret" lay-verify="required" autocomplete="off" placeholder="请输入AccessKey Secret"
					lay-reqText="请输入端口" class="layui-input" {notempty name="$config.accessKeySecret" }
					value="{$config.accessKeySecret}" {/notempty} style="width:300px;display: inline-block;">
				<span style="color:#999; font-size:12px;">如：JkfUaEA*******M3HE3FW</span>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray-4">Endpoint（地域节点）<font>*</font>
			</td>
			<td>
				<input type="text" name="Endpoint" autocomplete="off" lay-verify="required" placeholder="请输入Endpoint（地域节点）"
					lay-reqText="请输入Endpoint（地域节点）" class="layui-input" {notempty name="$config.Endpoint" }
					value="{$config.Endpoint}" {/notempty} style="width:300px;display: inline-block;">
				<span style="color:#999; font-size:12px;">如：oss-cn-beijing.******.com</span>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray-4">空间名<font>*</font>
			</td>
			<td>
				<input type="text" name="bucket" autocomplete="off" lay-verify="required" placeholder="请输入空间名"
					lay-reqText="请输入空间名" class="layui-input" {notempty name="$config.bucket" }
					value="{$config.bucket}" {/notempty} style="width:300px;display: inline-block;">
				<span style="color:#999; font-size:12px;">如：ceshi</span>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray-4">Bucket 域名<font>*</font>
			</td>
			<td>
				<input type="text" name="cdnurl" lay-verify="required" autocomplete="off" placeholder="请输入Bucket 域名"
					class="layui-input" {notempty name="$config.cdnurl" } value="{$config.cdnurl}" {/notempty}
					style="width:300px;display: inline-block;">
				<span style="color:#999; font-size:12px;">如：*****.oss-cn-beijing.*****.com</span>
			</td>
		</tr>

	</table>
	<div class="py-3">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<!-- <button lay-event="email" class="layui-btn">发送测试</button> -->
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','tinymce'];
	function gouguInit() {
		var form = layui.form, tool = layui.tool, tinymce = layui.tinymce;
		
		var edit = tinymce.render({
			selector: "#container",
			height: 300
		});
		//监听提交
		form.on('submit(webform)', function (data) {
			// data.field.template = tinyMCE.editors['container'].getContent();
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					parent.layui.tool.close(1000);
				}
			}
			console.log(data.field)
			tool.post("/admin/conf/edit", data.field, callback);
			return false;
		});

		$('body').on('click', '[lay-event="email"]', function () {
			layer.prompt({
				formType: 0,
				value: '',
				title: '输入接收测试邮件的邮箱',
				id: 'email_to'
			}, function (value, index, elem) {
				var isEmail = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
				if (value.length < 6 || !(isEmail.test(value))) {
					layer.tips('请正确输入邮箱', elem);
					return false;
				}
				$.ajax({
					url: "/home/api/email_test",
					data: { email: value },
					type: "post",
					beforeSend: function () {
						// 禁用按钮防止重复提交
						$("#email_to input").val('');
					},
					success: function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							layer.close(index);
						}
					}
				})
			});
			return false;
		})
	}
</script>
{/block}
<!-- /脚本 -->